package bTree.LeetCode;

import javax.swing.tree.TreeNode;

public class 二叉树展开为链表 {
    TreeNode proNode = null;
    public void flatten(TreeNode root) {
        dfs(root);
    }

    private void dfs(TreeNode node) {
        if(node==null){
            return;
        }
        dfs(node.right);
        dfs(node.left);
        if(proNode!=null){
            node.right=proNode;
            node.left=null;
        }
        proNode=node;
    }
}